<template>
  <div>
    <el-form ref="form" label-width="80px">
      <el-form-item label="是否有锁">
        <el-radio-group v-model="finalItem.testDevicePhone.isAssociated">
          <el-radio :label="true">有锁</el-radio>
          <el-radio :label="false">无锁</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="品质">
        <el-radio-group v-model="finalItem.testDevicePhone.quality">
          <el-radio label="A">A</el-radio>
          <el-radio label="B">B</el-radio>
          <el-radio label="C">C</el-radio>
          <el-radio label="D">D</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="状态">

        <el-radio-group v-model="finalItem.testDevicePhone.passed">
          <el-radio :label="true">PASS</el-radio>
          <el-radio :label="false">FAIL</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="成色">

        <el-radio-group v-model="finalItem.testDevicePhone.deviceCondition">
             <el-radio label="报废">报废</el-radio>
            <el-radio label="七成新">七成新</el-radio>
            <el-radio label="八成新">八成新</el-radio>
            <el-radio label="九成新">九成新</el-radio>
            <el-radio label="九五新">九五新</el-radio>
            <el-radio label="全新">全新</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { reqSubmit } from '../utils/api'
import _ from 'lodash'
export default {
  name: 'submit',
  created () {
    const param = this.$route.query.encode
    const data = decodeURIComponent(param)
    this.item = JSON.parse(data)
    this.finalItem = _.cloneDeep(this.item)
    // 默认品质B
    this.$set(this.finalItem.testDevicePhone, 'quality', 'B')
    this.$set(this.finalItem.testDevicePhone, 'isAssociated', null)
    this.$set(this.finalItem.testDevicePhone, 'passed', true)
    this.$set(this.finalItem.testDevicePhone, 'deviceCondition', null)
  },
  mounted () {},
  data () {
    return {
      flag: null,
      item: {},
      finalItem: null,
      value: '1'
    }
  },
  methods: {
    // 提交
    async onSubmit () {
      if (this.finalItem.testDevicePhone.isAssociated == null) {
        this.$message({
          message: '你还没有选择是否有锁',
          type: 'warning'
        })
        return
      }
      if (this.finalItem.testDevicePhone.quality == null) {
        this.$message({
          message: '你还没有选择品质',
          type: 'warning'
        })
        return
      }
      if (this.finalItem.testDevicePhone.passed == null) {
        this.$message({
          message: '你还没有选择状态',
          type: 'warning'
        })
        return
      }
      if (this.finalItem.testDevicePhone.deviceCondition == null) {
        this.$message({
          message: '你还没有选择成色',
          type: 'warning'
        })
        return
      }
      const res = await reqSubmit(this.finalItem)
      if (res.data.code == 0) {
        this.$router.push('/detail?id=' + this.finalItem.testDevicePhone.id)
      } else {
        this.$message({
          message: res.data.msg,
          type: 'warning'
        })
      }
    }
  }
}
</script>

<style soped lang="less">
</style>
